/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.apt.hobbiestag.process;

import com.apt.bean.Hobbies;
import com.apt.tag.Connect_DB;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.HashMap;

/**
 *
 * @author Bach
 */
public class GetListLiking {
    
     public static HashMap<Integer, Hobbies> getListHobbies(String lik_Id) {
        HashMap<Integer, Hobbies> listP = new HashMap<Integer, Hobbies>();
        PreparedStatement ps = null;
        ResultSet rs = null;
        Connection conn = null;
//        where Payment_Type_Status=1
         String query = "SELECT  [Liking_Model_Id]\n"
                 + "      ,[Liking_Model_Name]\n"
                 + "      ,[Liking_Model_Status]\n"
                 + "      ,[Liking_Id]\n"
                 + "  FROM [Matrimony].[dbo].[Liking_Models]"
                 + "Where [Liking_Id]=?";
       
        try {
            conn = Connect_DB.getConnection();
            if (conn != null) {
                ps = conn.prepareStatement(query);
                ps.setInt(1, Integer.parseInt(lik_Id));
                rs = ps.executeQuery();
                int key = 1;
                String liking_Id;
                String liking_Model_Name;
                String liking_Model_Status;
                String liking_Model_Id;

                while (rs.next()) {

                    liking_Id = rs.getString("Liking_Id");
                    liking_Model_Id = rs.getString("Liking_Model_Id");
                    liking_Model_Name = rs.getString("Liking_Model_Name");
                    liking_Model_Status = rs.getString("Liking_Model_Status");
                    Hobbies p = new Hobbies(liking_Model_Id, liking_Id, liking_Model_Name, liking_Model_Status);
                    listP.put(key, p);
                    key++;
                }
            } else {
                System.out.println("Connect is null");
            }

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            Connect_DB.close(rs, null, ps, conn);
        }
        return listP;
    }
}


//    public static HashMap<Integer, Liking> getListHobbies(String liking_M_Id) {
//        HashMap<Integer, Liking> listP = new HashMap<Integer, Liking>();
//        PreparedStatement ps = null;
//        ResultSet rs = null;
//        Connection conn = null;
////        where Payment_Type_Status=1
//        String query = "SELECT  [Liking_Status]\n"
//                + "      ,[Liking_Name]\n"
//                + "      ,[Liking_Id]\n"
//                + "  FROM [Matrimony].[dbo].[Liking_Cates]\n"
//                + "  where [Liking_Model_Id]=?";
//
////        SELECT [Liking_Status]
////      ,[Liking_Name]
////      ,[Liking_Id]
////  FROM [Matrimony].[dbo].[Liking_Cates]
//        try {
//            conn = Connect_DB.getConnection();
//            if (conn != null) {
//                ps = conn.prepareStatement(query);
//                ps.setInt(1, Integer.parseInt(liking_M_Id));
//                rs = ps.executeQuery();
//                int key = 1;
//                String liking_Name;
//                String liking_Id;
////                String liking_Model_Id;
//                String liking_Status;
//
//                while (rs.next()) {
//                    liking_Name = rs.getString("Liking_Name");
//                    liking_Id = rs.getString("Liking_Id");
////                    liking_Model_Id = rs.getString("Liking_Model_Id");
//                    liking_Status = rs.getString("Liking_Status");
//                    Liking l = new Liking(liking_Name, liking_Id, liking_Status);//liking_Name, liking_Id, liking_Model_Id, liking_Status);
//                    listP.put(key, l);
//                    key++;
//                }
//                System.out.println("so luong ban ghi" + key);
//            } else {
//                System.out.println("Connect is null");
//            }
//
//        } catch (Exception e) {
//            e.printStackTrace();
//        } finally {
//            Connect_DB.close(rs, null, ps, conn);
//        }
//        return listP;
//    }